<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>jquery封装的ajax</title>
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
	</head>
	<body>
		<h2>该页面练习：jQuery封装的ajax的其他配置</h2>
		<button onclick="getCarList()">获取汽车列表</button> <br></br>
		<button onclick="off()">不想等了，中断请求</button><br></br>
		<input type="text"><br></br>
		<button>1111</button><br></br>
		<button>2222</button><br></br>
		<button>3333</button>
		
		<script type="text/javascript" >
			let xhr 
			let isLoading = false
			function getCarList(){
				if(isLoading) xhr.abort()
				isLoading = true
				xhr = $.ajax({
					url:'http://localhost:5000/cars',
					method:'GET',
					// dataType:'text', //用于配置响应数据的编码格式，一般不手动指定，靠jQuery自己判断
					// timeout:3000, //超时时间
					// async:false, //控制本次ajax请求是同步还是异步
					success(data){
						console.log('请求成功了',data)
						isLoading = false
					},
					error(_,__,errMsg){
						console.log('获取数据失败',errMsg)
						isLoading = false
					}
				})
			}

			function off(){
				xhr.abort()
			}
		</script>
	</body>
</html>